﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace KIS公有云测试.Tools
{
    public class INIHelper
    {
        public static string ReadIniValue(string section, string key)
        {
            string currentSection = "";
            string iniPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "API_account.ini");

            using (var reader = new StreamReader(iniPath))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    line = line.Trim();
                    if (line.StartsWith("["))
                    {
                        currentSection = line.Trim('[', ']');
                    }
                    else if (currentSection == section && line.Contains("="))
                    {
                        string[] parts = line.Split(new[] { '=' }, 2);
                        if (parts[0].Trim() == key)
                            return parts[1].Trim();
                    }
                }
            }
            return null;
        }
    }
}